import Vue from 'vue'
import Vuex from 'vuex'
import song from './song'
import configure from './configure'
import user from './user'

Vue.use(Vuex)


const store = new Vuex.Store({
  modules:{
    song,
    configure,
    user,
  },
  state: {
    isLogin: "0",
    userName: "",

  },
  getters: {
    isLogin: state => state.isLogin,
    userName: state => state.userName,
  },
  mutations: {
    setIsLogin: (state, isLogin) => {
      state.isLogin = isLogin;
      window.sessionStorage.isLogin = isLogin;
    },
    setUserName: (state, userName) => {
      state.userName = userName;
      window.sessionStorage.userName = userName;
    },
  },
  actions: {
    asyncUpdateUserName(context, userName) {
      context.commit("setUserName", userName);
    },
    asyncUpdateIsLogin(context, isLogin) {
      context.commit("setIsLogin", isLogin);
    },
  },
})




export default store;
